package com.nanychuan.blogback.pojo;

import java.util.List;

/**
 * @author 往
 */
public class PageBean<T> {
    //获取前端传过来的page数据

    private int pageNum;//当前页
    private int pageSize;//每页显示的记录数
    private int totalCount;//总记录数
    private int totalPage;//总页数
    private int startIndex;//开始索引
    private int start;//起始页
    private int end;//结束页
    private List<T> articleList;//存放数据的集合

    //构造方法
    public PageBean(int pageNum, int pageSize, int totalCount) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalCount = totalCount;

        //总页数
        if (totalCount % pageSize == 0) {
            //刚好每页显示完
            this.totalPage = totalCount;
        } else {
            //每页不能显示完
            this.totalPage = totalCount / pageSize + 1;
        }
        //开始索引
        this.startIndex = (pageNum - 1) * pageSize;
        this.start = 1;
        this.end = 5;

        //计算显示页数
        if (totalPage <= 5) {
            //结束页等于总页数
            this.end = this.totalPage;
        } else {
            //总页数大于5
            this.start = pageNum - 2;
            this.end = pageNum + 2;

            if (start<0){
                //如果当前页是第1页就不重新计算页数
                this.start = 1;
                this.end = 5;
            }
            if (end>this.totalPage){
                //如果当前页是最后一页，也不重新计算页数
                this.end = totalPage;
                this.start = end - 5;
            }
        }
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public List<T> getArticleList() {
        return articleList;
    }

    public void setArticleList(List<T> articleList) {
        this.articleList = articleList;
    }
}
